package com.beiben.statistics.controller;

import com.beiben.statistics.service.IWorkService;
import com.beiben.statistics.vo.AbillityDataVo;
import com.beiben.statistics.vo.LineDataVo;
import com.beiben.statistics.vo.NameValueVo;
import com.beiben.statistics.vo.RecordSearchParamVo;
import com.beiben.work.process.domain.FileProcessUser;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.domain.entity.SysUser;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.common.exception.BaseException;
import com.ruoyi.common.utils.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.text.ParseException;
import java.util.List;

/**
 * 文件工时统计看板Controller
 *
 * @author xgq
 * @date 2020-10-09
 */
@RestController
@RequestMapping("/statistics/work")
public class WorkController  extends BaseController {

    @Autowired
    private IWorkService workService;

    /**
     * 查询所的总工时
     */
    @PostMapping("/dept/suo")
    @ResponseBody
    public List<NameValueVo> selectAbilityDeptSuo(RecordSearchParamVo recordSearchParamVo, HttpServletRequest request, HttpServletResponse response){
        List<NameValueVo> list = null;
        try {
            list = workService.selectWorkDeptSuo(recordSearchParamVo);
        } catch (ParseException e) {
            e.printStackTrace();
            throw new BaseException("日期转换错误");
        }
        return list;
    }

    /**
     * 查询科室的总工时
     */
    @PostMapping("/dept/shi")
    @ResponseBody
    public List<NameValueVo> selectAbilityDeptShi(RecordSearchParamVo recordSearchParamVo, HttpServletRequest request, HttpServletResponse response){
        List<NameValueVo> list = null;
        try {
            list = workService.selectWorkDeptShi(recordSearchParamVo);
        } catch (ParseException e) {
            e.printStackTrace();
            throw new BaseException("日期转换错误");
        }
        return list;
    }

    /**
     * 查询所的平均工作工时
     */
    @PostMapping("/dept/ave/suo")
    @ResponseBody
    public List<NameValueVo> selectAbilityDeptAverageSuo(RecordSearchParamVo recordSearchParamVo, HttpServletRequest request, HttpServletResponse response){
        List<NameValueVo> list = null;
        try {
            list = workService.selectAbilityDeptAverageSuo(recordSearchParamVo);
        } catch (ParseException e) {
            e.printStackTrace();
            throw new BaseException("日期转换错误");
        }
        return list;
    }

    /**
     * 查询科室的平均工作工时
     */
    @PostMapping("/dept/ave/shi")
    @ResponseBody
    public List<NameValueVo> selectAbilityDeptAverageShi(RecordSearchParamVo recordSearchParamVo, HttpServletRequest request, HttpServletResponse response){
        List<NameValueVo> list = null;
        try {
            list = workService.selectAbilityDeptAverageShi(recordSearchParamVo);
        } catch (ParseException e) {
            e.printStackTrace();
            throw new BaseException("日期转换错误");
        }
        return list;
    }

    /**
     * 查询人员总工时
     */
    @PostMapping("/dept/people")
    @ResponseBody
    public List<NameValueVo> selectWorkTotalPeople(RecordSearchParamVo recordSearchParamVo, HttpServletRequest request, HttpServletResponse response){
        List<NameValueVo> list = null;
        try {
            list = workService.selectWorkTotalPeople(recordSearchParamVo);
        } catch (ParseException e) {
            e.printStackTrace();
            throw new BaseException("日期转换错误");
        }
        return list;
    }

    /**
     * 查询人员工作饱和度
     */
    @PostMapping("/dept/avg/people")
    @ResponseBody
    public List<NameValueVo> selectWorkAvgPeople(RecordSearchParamVo recordSearchParamVo, HttpServletRequest request, HttpServletResponse response){
        List<NameValueVo> list = null;
        try {
            list = workService.selectWorkAvgPeople(recordSearchParamVo);
        } catch (ParseException e) {
            e.printStackTrace();
            throw new BaseException("日期转换错误");
        }
        return list;
    }


    /**
     * 查询人员工作总量曲线（近30天）
     */
    @PostMapping("/total/line/people")
    @ResponseBody
    public List<LineDataVo> selectTotalLinePeople(RecordSearchParamVo recordSearchParamVo, HttpServletRequest request, HttpServletResponse response){
        List<LineDataVo> list = null;
        try {
            list = workService.selectWorkLinePeople(recordSearchParamVo);
        } catch (ParseException e) {
            e.printStackTrace();
            throw new BaseException("日期转换错误");
        }
        return list;
    }

    /**
     * 查询人员工作饱和度曲线（近30天）
     */
    @PostMapping("/avg/line/people")
    @ResponseBody
    public List<LineDataVo> selectAvgLinePeople(RecordSearchParamVo recordSearchParamVo, HttpServletRequest request, HttpServletResponse response){
        List<LineDataVo> list = null;
        try {
            list = workService.selectWorkAvgLinePeople(recordSearchParamVo);
        } catch (ParseException e) {
            e.printStackTrace();
            throw new BaseException("日期转换错误");
        }
        return list;
    }

    /**
     * 查询统计所的质量问题统计（近30天）
     */
    @PostMapping("/quality/bar/suo")
    @ResponseBody
    public List<NameValueVo> selectWorkQualityCount(RecordSearchParamVo recordSearchParamVo, HttpServletRequest request, HttpServletResponse response){
        List<NameValueVo> list = null;
        try {
            list = workService.selectWorkQualityCount(recordSearchParamVo);
        } catch (ParseException e) {
            e.printStackTrace();
            throw new BaseException("日期转换错误");
        }
        return list;
    }

    /**
     * 查询统计科室的质量问题统计（近30天）
     */
    @PostMapping("/quality/bar/shi")
    @ResponseBody
    public List<NameValueVo> selectWorkQualityCountShi(RecordSearchParamVo recordSearchParamVo, HttpServletRequest request, HttpServletResponse response){
        List<NameValueVo> list = null;
        try {
            list = workService.selectWorkQualityCountShi(recordSearchParamVo);
        } catch (ParseException e) {
            e.printStackTrace();
            throw new BaseException("日期转换错误");
        }
        return list;
    }

    /**
     * 查询统计组的质量问题统计（近30天）
     */
    @PostMapping("/quality/bar/zu")
    @ResponseBody
    public List<NameValueVo> selectWorkQualityCountZu(RecordSearchParamVo recordSearchParamVo, HttpServletRequest request, HttpServletResponse response){
        List<NameValueVo> list = null;
        try {
            list = workService.selectWorkQualityCountZu(recordSearchParamVo);
        } catch (ParseException e) {
            e.printStackTrace();
            throw new BaseException("日期转换错误");
        }
        return list;
    }

    /**
     * 查询统计组的质量问题统计（近30天） 排名前十
     */
    @PostMapping("/quality/bar/rank")
    @ResponseBody
    public List<NameValueVo> selectWorkQualityCountZuRank(RecordSearchParamVo recordSearchParamVo, HttpServletRequest request, HttpServletResponse response){
        List<NameValueVo> list = null;
        try {
            list = workService.selectWorkQualityCountZuRank(recordSearchParamVo);
        } catch (ParseException e) {
            e.printStackTrace();
            throw new BaseException("日期转换错误");
        }
        return list;
    }

    /**
     * 按所统计质量问题总工作量（质量单据小时数）
     */
    @PostMapping("/count/bar/suo")
    @ResponseBody
    public List<NameValueVo> selectWorkCountSuo(RecordSearchParamVo recordSearchParamVo, HttpServletRequest request, HttpServletResponse response){
        List<NameValueVo> list = null;
        try {
            list = workService.selectWorkCountSuo(recordSearchParamVo);
        } catch (ParseException e) {
            e.printStackTrace();
            throw new BaseException("日期转换错误");
        }
        return list;
    }

    /**
     * 按科室统计质量问题总工作量（小时数）
     */
    @PostMapping("/count/bar/shi")
    @ResponseBody
    public List<NameValueVo> selectWorkCountShi(RecordSearchParamVo recordSearchParamVo, HttpServletRequest request, HttpServletResponse response){
        List<NameValueVo> list = null;
        try {
            list = workService.selectWorkCountShi(recordSearchParamVo);
        } catch (ParseException e) {
            e.printStackTrace();
            throw new BaseException("日期转换错误");
        }
        return list;
    }

    /**
     * 按人员统计质量问题总工作量（小时数）
     */
    @PostMapping("/count/bar/people")
    @ResponseBody
    public List<NameValueVo> selectWorkCountPeople(RecordSearchParamVo recordSearchParamVo, HttpServletRequest request, HttpServletResponse response){
        List<NameValueVo> list = null;
        try {
            list = workService.selectWorkCountPeople(recordSearchParamVo);
        } catch (ParseException e) {
            e.printStackTrace();
            throw new BaseException("日期转换错误");
        }
        return list;
    }

    /**
     * 查询质量问题曲线（近30天）
     */
    @PostMapping("/total/line/quality")
    @ResponseBody
    public List<NameValueVo> selectTotalLineQuality(RecordSearchParamVo recordSearchParamVo, HttpServletRequest request, HttpServletResponse response){
        List<NameValueVo> list = null;
        try {
            list = workService.selectTotalLineQuality(recordSearchParamVo);
        } catch (ParseException e) {
            e.printStackTrace();
            throw new BaseException("日期转换错误");
        }
        return list;
    }

    /**
     * 待办工作-项目工作
     *
     * @param recordSearchParamVo
     * @return
     * @throws ParseException
     */
    @GetMapping("/project/list")
    public TableDataInfo projectList(RecordSearchParamVo recordSearchParamVo) throws ParseException {
        startPage();
        List<FileProcessUser> list = workService.selectMyWaitWorkProjectList(recordSearchParamVo);
        return getDataTable(list);
    }

    /**
     * 待办工作-日常工作
     *
     * @param recordSearchParamVo
     * @return
     * @throws ParseException
     */
    @GetMapping("/process/list")
    public TableDataInfo processList(RecordSearchParamVo recordSearchParamVo) throws ParseException {
        startPage();
        List<FileProcessUser> list = workService.selectMyWaitWorkList(recordSearchParamVo);
        return getDataTable(list);
    }

    /**
     * 查询代办工作统计
     */
    @GetMapping("/statistics")
    public AjaxResult statistics(RecordSearchParamVo recordSearchParamVor) {
        return AjaxResult.success(workService.selectCountWork(recordSearchParamVor));
    }

    /**
     * 待办工作-日常工作质量问题
     *
     * @param recordSearchParamVo
     * @return
     * @throws ParseException
     */
    @GetMapping("/process/quality/list")
    public TableDataInfo processQualityList(RecordSearchParamVo recordSearchParamVo) throws ParseException {
        startPage();
        List<FileProcessUser> list = workService.selectQualityWorkList(recordSearchParamVo);
        return getDataTable(list);
    }

    /**
     * 查询代办工作统计- 质量问题
     */
    @GetMapping("/quality/statistics")
    public AjaxResult qualityStatistics(RecordSearchParamVo recordSearchParamVor) {
        return AjaxResult.success(workService.selectQualityCountWork(recordSearchParamVor));
    }
}
